package com.secondHandPlatform.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.secondHandPlatform.Util.Result;
import com.secondHandPlatform.service.impl.FocusServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author team
 * @since 2023-05-18
 */
@RestController
@RequestMapping("/focus")
public class FocusController {

    @Autowired
    FocusServiceImpl focusService;

    @GetMapping("/findBookmark")
    public Result findBookmark(@RequestParam(value = "currentPage", defaultValue = "1") int curPage,
                               @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
                               @RequestParam(value = "userId") int userId) {

        Page<Object> objects = PageHelper.startPage(curPage, pageSize);
        List<Map<String, Object>> goods = focusService.selectFocusByUser(userId);

        HashMap<String, Object> map = new HashMap<>();
        map.put("data",goods);
        map.put("total",objects.toPageInfo().getTotal());
        return new Result().success(map);
    }
}
